package com.kgc.warehouse.bussness.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kgc.warehouse.bussness.entity.*;
import com.kgc.warehouse.bussness.mapper.*;
import com.kgc.warehouse.bussness.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author main
 * @description 针对表【bus_goods】的数据库操作Service实现
 * @createDate 2023-02-04 08:48:32
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService{
    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private InportMapper inportMapper;
    @Resource
    private OutportMapper outportMapper;
    @Resource
    private SalesbackMapper salesbackMapper;
    @Resource
    private SalesMapper salesMapper;

    @Override
    public void deleteGoodsById(Integer id) {
        //根据商品id删进货信息
        LambdaQueryWrapper<Inport> inportLambdaQueryWrapper = new LambdaQueryWrapper<>();
        inportLambdaQueryWrapper.eq(Inport::getGoodsid,id);
        inportMapper.delete(inportLambdaQueryWrapper);
        //根据商品id删退货信息
        LambdaQueryWrapper<Outport> outportLambdaQueryWrapper = new LambdaQueryWrapper<>();
        outportLambdaQueryWrapper.eq(Outport::getGoodsid,id);
        outportMapper.delete(outportLambdaQueryWrapper);
        //根据商品id删销售信息
        LambdaQueryWrapper<Sales> salesLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesLambdaQueryWrapper.eq(Sales::getGoodsid,id);
        salesMapper.delete(salesLambdaQueryWrapper);
        //根据商品id删销售退货信息
        LambdaQueryWrapper<Salesback> salesbackLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesbackLambdaQueryWrapper.eq(Salesback::getGoodsid,id);
        salesbackMapper.delete(salesbackLambdaQueryWrapper);

        //删除商品
        goodsMapper.deleteById(id);
    }
}




